﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:helpers="clr-namespace:UColor.Core.Helpers;assembly=UColor.Core"
    xmlns:demoparts="clr-namespace:UColor.Core.Parts;assembly=UColor.Core"
    xmlns:dxwindow="clr-namespace:DevExpress.Internal.DXWindow;assembly=UColor.Core">

    <Image x:Key="MinimizeButtonImage" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Center" />
    <Image x:Key="RestoreButtonImage" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Center" />
    <Image x:Key="MaximizeButtonImage" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Center" />
    <Image x:Key="CloseButtonImage" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Center" />

    <dxwindow:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" Invert="False" />
    <dxwindow:BooleanToVisibilityConverter x:Key="InvertedBooleanToVisibilityConverter" Invert="True" />
    <Style x:Key="WindowButtonStyle" TargetType="helpers:ButtonExt">
        <Setter Property="Padding" Value="5" />
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="helpers:ButtonExt">
                    <Grid Background="#00000000">
                        <Grid.Resources>
                            <helpers:SelectConverter x:Key="OpacityConverter">
                                <helpers:SelectState Key="Normal" Value="{helpers:DoubleValue S=0.55}" />
                                <helpers:SelectState Key="MouseOver" Value="{helpers:DoubleValue S=1}" />
                                <helpers:SelectState Key="Pressed" Value="{helpers:DoubleValue S=0.35}" />
                                <helpers:SelectState Key="Disabled" Value="{helpers:DoubleValue S=0.15}" />
                            </helpers:SelectConverter>
                            <helpers:SelectConverter x:Key="BackgoundConverter">
                                <helpers:SelectState Key="Normal" Value="{helpers:BrushValue S=Transparent}" />
                                <helpers:SelectState Key="MouseOver" Value="{helpers:BrushValue S=#FFE9E9E9}" />
                                <helpers:SelectState Key="Pressed" Value="{helpers:BrushValue S=#FFE9E9E9}" />
                                <helpers:SelectState Key="Disabled" Value="{helpers:BrushValue S=Transparent}" />
                            </helpers:SelectConverter>
                        </Grid.Resources>
                        <Border Background="{helpers:SelectBinding Binding={Binding CommonState, RelativeSource={RelativeSource TemplatedParent}}, Converter={StaticResource BackgoundConverter}}">
                            <ContentPresenter x:Name="contentPresenter" Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                Opacity="{helpers:SelectBinding Binding={Binding CommonState, RelativeSource={RelativeSource TemplatedParent}}, Converter={StaticResource OpacityConverter}}" />
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <ControlTemplate TargetType="{x:Type dxwindow:DXWindow}" x:Key="DXWindowTemplate">
        <Grid x:Name="Root_Grid" Height="Auto" Margin="0,0,0,0" VerticalAlignment="Stretch">
            <AdornerDecorator ClipToBounds="True" x:Name="PART_WindowAdornerDecorator">
                <ContentPresenter ContentTemplate="{TemplateBinding WindowTemplate}" Height="Auto" Width="Auto" x:Name="PART_RootContentPresenter" DataContext="{TemplateBinding DataContext}">
                    <ContentPresenter.Content>
                        <ContentControl DataContext="{TemplateBinding DataContext}">
                            <ContentControl.ContentTemplate>
                                <Binding Path="ContentTemplate" RelativeSource="{RelativeSource TemplatedParent}" />
                            </ContentControl.ContentTemplate>
                            <ContentControl.Content>
                                <Binding Path="Content" RelativeSource="{RelativeSource TemplatedParent}" />
                            </ContentControl.Content>
                        </ContentControl>
                    </ContentPresenter.Content>
                </ContentPresenter>
            </AdornerDecorator>
        </Grid>
    </ControlTemplate>
    <ControlTemplate TargetType="{x:Type dxwindow:DXWindow}" x:Key="DXWindowEmptyTemplate">
        <Grid x:Name="Root_Grid" Height="Auto" Margin="0,0,0,0" VerticalAlignment="Stretch">
            <AdornerDecorator ClipToBounds="True" x:Name="PART_WindowAdornerDecorator">
                <ContentPresenter ContentTemplate="{TemplateBinding WindowTemplate}" Height="Auto" Width="Auto" x:Name="PART_RootContentPresenter">
                    <ContentPresenter.Content>
                        <Border />
                    </ContentPresenter.Content>
                </ContentPresenter>
            </AdornerDecorator>
        </Grid>
    </ControlTemplate>
    <ControlTemplate x:Key="FloatingContainerResizeFrame" TargetType="{x:Type Control}">
        <Grid Opacity="0" Panel.ZIndex="2" x:Name="FloatPaneBorders">
            <Grid.RowDefinitions>
                <RowDefinition Height="10" />
                <RowDefinition Height="*" />
                <RowDefinition Height="10" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="10" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="10" />
            </Grid.ColumnDefinitions>
            <Path x:Name="Part_TopLeft" Cursor="SizeNWSE" Stretch="Fill" Fill="black" Data="F1 M 414,287L 410,287L 410,281L 410,277L 414,277L 420,277L 420,281L 414,281L 414,287 Z " HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top" Width="15" Height="15" Grid.Column="0" Grid.Row="0" />
            <Path x:Name="Part_TopRight" Cursor="SizeNESW" Stretch="Fill" Fill="black" Data="F1 M 430,294L 430,290L 436,290L 440,290L 440,294L 440,300L 436,300L 436,294L 430,294 Z " HorizontalAlignment="Right" Margin="0" VerticalAlignment="Top" Width="15" Height="15" Grid.Column="2" Grid.Row="0" />
            <Path x:Name="Part_BottomRight" Cursor="SizeNWSE" Stretch="Fill" Fill="black" Data="F1 M 393,279L 397,279L 397,285L 397,289L 393,289L 387,289L 387,285L 393,285L 393,279 Z " HorizontalAlignment="Right" Margin="0" VerticalAlignment="Bottom" Width="15" Height="15" Grid.Column="2" Grid.Row="2" />
            <Path x:Name="Part_BottomLeft" Cursor="SizeNESW" Stretch="Fill" Fill="black" Data="F1 M 416,312L 416,316L 410,316L 406,316L 406,312L 406,306L 410,306L 410,312L 416,312 Z " HorizontalAlignment="Left" Margin="0" VerticalAlignment="Bottom" Width="15" Height="15" Grid.Column="0" Grid.Row="2" Grid.RowSpan="1" />
            <Rectangle Stretch="Fill" HorizontalAlignment="Stretch" Fill="black" x:Name="Part_Bottom" VerticalAlignment="Bottom" Width="Auto" Height="6" Grid.Column="1" Grid.Row="2" Cursor="SizeNS" />
            <Rectangle Stretch="Fill" HorizontalAlignment="Stretch" Fill="black" x:Name="Part_Top" VerticalAlignment="Top" Width="Auto" Height="6" Grid.Column="1" Grid.Row="0" Cursor="SizeNS" />
            <Rectangle Stretch="Fill" HorizontalAlignment="Left" Fill="black" x:Name="Part_Left" VerticalAlignment="Stretch" Width="6" Height="Auto" Grid.Column="0" Grid.Row="1" Cursor="SizeWE" />
            <Rectangle Stretch="Fill" HorizontalAlignment="Right" Fill="black" x:Name="Part_Right" VerticalAlignment="Stretch" Width="6" Height="Auto" Grid.Column="2" Grid.Row="1" Cursor="SizeWE" />
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="FlowDirection" Value="RightToLeft">
                <Setter Property="Cursor" TargetName="Part_TopLeft" Value="SizeNESW" />
                <Setter Property="Cursor" TargetName="Part_TopRight" Value="SizeNWSE" />
                <Setter Property="Cursor" TargetName="Part_BottomLeft" Value="SizeNWSE" />
                <Setter Property="Cursor" TargetName="Part_BottomRight" Value="SizeNESW" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    <DataTemplate x:Key="FloatingContainerCaptionTemplate">
        <Grid Height="Auto">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Image x:Name="PART_Icon" Width="Auto" Height="Auto" Margin="6,3,0,3" Stretch="None" Grid.Column="0" Source="{Binding Path=(dxwindow:FloatingContainer.FloatingContainer).Icon, RelativeSource={RelativeSource AncestorType=ContentPresenter}}" />
            <dxwindow:FloatingContainerHeaderPanel Grid.Column="1">
                <TextBlock x:Name="PART_Text" Background="{x:Null}" Foreground="#FFD4E4F8" Margin="6,3,6,3" VerticalAlignment="Center" IsHitTestVisible="False" Text="{Binding Path=(dxwindow:FloatingContainer.FloatingContainer).Caption, RelativeSource={RelativeSource AncestorType=ContentPresenter}}" />
            </dxwindow:FloatingContainerHeaderPanel>
        </Grid>
        <DataTemplate.Triggers>
            <Trigger Property="Source" SourceName="PART_Icon" Value="{x:Null}">
                <Setter TargetName="PART_Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
        </DataTemplate.Triggers>
    </DataTemplate>
    <DataTemplate x:Key="DemoWindowFloatingContainerTemplate">
        <Grid>
            <Border x:Name="FloatingContainerBorder">
                <Grid>
                    <Border BorderBrush="#FF9F9F9F" BorderThickness="1" Background="White" />
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Border x:Name="FloatingContainerHeader" Background="Transparent" Panel.ZIndex="99">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <ContentPresenter x:Name="PART_CaptionContentPresenter" Content="{x:Null}" Grid.Column="0" Panel.ZIndex="100" ContentTemplate="{StaticResource FloatingContainerCaptionTemplate}" />
                                <Thumb x:Name="PART_DragWidget">
                                    <Thumb.Template>
                                        <ControlTemplate TargetType="{x:Type Thumb}">
                                            <Border Background="Transparent" />
                                        </ControlTemplate>
                                    </Thumb.Template>
                                </Thumb>
                                <StackPanel Margin="2" Grid.Column="1" Orientation="Horizontal" x:Name="stackPanel" VerticalAlignment="Center">
                                    <helpers:ButtonExt x:Name="PART_Minimize" Style="{StaticResource WindowButtonStyle}" Margin="2" Content="{StaticResource MinimizeButtonImage}" />
                                    <helpers:ButtonExt x:Name="PART_Restore" Style="{StaticResource WindowButtonStyle}" Margin="2" Content="{StaticResource RestoreButtonImage}"
                                                    Visibility="{Binding Path=(dxwindow:FloatingContainer.IsMaximized), Converter={StaticResource BooleanToVisibilityConverter}}" />
                                    <helpers:ButtonExt x:Name="PART_Maximize" Style="{StaticResource WindowButtonStyle}" Margin="2" Content="{StaticResource MaximizeButtonImage}"
                                                    Visibility="{Binding Path=(dxwindow:FloatingContainer.IsMaximized), Converter={StaticResource InvertedBooleanToVisibilityConverter}}" />
                                    <helpers:ButtonExt x:Name="PART_CloseButton" Style="{StaticResource WindowButtonStyle}" Margin="2" Content="{StaticResource CloseButtonImage}" />
                                </StackPanel>
                            </Grid>
                        </Border>
                        <Border x:Name="FloatingContainerBody" Grid.RowSpan="2">
                            <ContentPresenter x:Name="PART_ContainerContent" Content="{Binding}" />
                        </Border>
                    </Grid>
                </Grid>
            </Border>
            <Control x:Name="PART_ResizeFrame" Focusable="False" IsTabStop="False" Template="{StaticResource FloatingContainerResizeFrame}" />
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Path=(dxwindow:FloatingContainer.FloatingContainer).AllowSizing, RelativeSource={RelativeSource Self}}" Value="False">
                <Setter Property="Visibility" TargetName="PART_ResizeFrame" Value="Collapsed" />
            </DataTrigger>
            <DataTrigger Binding="{Binding Path=(dxwindow:FloatingContainer.IsMaximized)}" Value="True">
                <Setter Property="Margin" TargetName="FloatingContainerBorder" Value="-1" />
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
    <Style x:Key="Window" TargetType="dxwindow:DXWindow">
        <Setter Property="Background" Value="#FF544765"/>
        <Setter Property="ShowTitle" Value="False" />
        <Setter Property="ShowIcon" Value="False" />
        <Setter Property="ResizeMode" Value="CanResize" />
        <Setter Property="Template" Value="{StaticResource DXWindowTemplate}" />
        <Setter Property="WindowTemplate" Value="{StaticResource DemoWindowFloatingContainerTemplate}" />
        <Style.Triggers>
            <Trigger Property="HasContent" Value="False">
                <Setter Property="Template" Value="{StaticResource DXWindowEmptyTemplate}" />
            </Trigger>
        </Style.Triggers>
    </Style>
</ResourceDictionary>